import {WebRequestTaskStatus} from "./WebRequestTaskStatus";
import {ReferencePool} from "../Base/ReferencePool/ReferencePool";
import {TaskPoolTaskBase} from "../Base/TaskPool/TaskPoolTaskBase";

export class WebRequestTask extends TaskPoolTaskBase {
    get webrequesturi(): string {
        return this._webrequesturi;
    }

    get postdata(): number[] {
        return this._postdata;
    }

    get timeout(): number {
        return this._timeout;
    }

    get userdata() {
        return this._userdata;
    }

    get Status(): WebRequestTaskStatus {
        return this._Status;
    }

    set Status(value: WebRequestTaskStatus) {
        this._Status = value;
    }

    private static s_serial: number = 0;
    private _Status: WebRequestTaskStatus;
    private _webrequesturi: string;
    private _postdata: number[];
    private _timeout: number;
    private _userdata;

    constructor() {
        super();
        this._Status = WebRequestTaskStatus.Todo;
        this._webrequesturi = null;
        this._postdata = null;
        this._timeout = 0;
        this._userdata = null;

    }

    public static Create(webRequestUri: string, postData: number[], priority: number, timeout: number, userData): WebRequestTask {
        let webRequestTask: WebRequestTask = ReferencePool.Acquire(WebRequestTask);
        webRequestTask.Initialize(++this.s_serial, priority);
        webRequestTask._webrequesturi = webRequestUri;
        webRequestTask._postdata = postData;
        webRequestTask._timeout = timeout;
        webRequestTask._userdata = userData;
        return webRequestTask;
    }


    Clear() {
        super.Clear();
        this._Status = WebRequestTaskStatus.Todo;
        this._webrequesturi = null;
        this._postdata = null;
        this._timeout = 0;
        this._userdata = null;
    }
}